var params = new Array();
webix.ready(function() {
			var clickColumnId;
			var clickRowId;

			webix.Date.startOnMonday = true;
			var phone_options = {
				"1" : "开",
				"2" : "关"
			};
			var email_options = {
					"1" : "开",
					"2" : "关"
				};
			var calendar_window = webix.ui({
				view : "window",
				id : "my_window",
				position : 'center',
				move : true,
				head : {
					view : "toolbar",
					margin : -4,
					cols : [ {}, {
						view : "icon",
						icon : "times-circle",
						click : "$$('my_window').hide();"
					} ]
				},
				body : {
					view : "calendar",
					id : "my_calendar",
					type : "time",
				},
			});
			var my_template = {
				template : "<span style='font-size:20px; font-weight:bold; color:#3498DB'; >通知设置</span>&nbsp;/&nbsp;&nbsp;notifySet",
				height : 45,
				borderless : true
			};
			var my_toolbar = {
				view : "toolbar",
				elements : [ {
					view : "button",
					value : "修改",
					width : 100,
					click : 'updateRow()'
				}, {
					view : "button",
					value : "保存",
					width : 50,
					click : "save"
				},{
					id:"desc",
					view:"label",
					label:"邮箱与手机号如要填写多个请用 , 隔开"
				} ]
			};
			var my_datatable = {
				height : 680,
				view : "datatable",
				id : "mydatatable",
				columns : [ {
					id : "title",
					header : "标题",
					fillspace : true
				}, {
					id : "alias",
					header : "别名",
					fillspace : true
				}, {
					id : "emailSwitch",
					header : "邮箱开关",
					width:100,
					template : function(obj, type) {
						if (obj.emailSwitch == "1") {
							return "开";
						} else if (obj.emailSwitch == "2") {
							return "关";
						}
					},
					editor : "select",
					options : email_options
				}, {
					id : "email",
					header : "邮箱",
					fillspace : true,
					sort : "string",
					editor : "text"
				},  {
					id : "phoneSwitch",
					header : "手机开关",
					width:100,
					template : function(obj, type) {
						if (obj.phoneSwitch == "1") {
							return "开";
						} else if (obj.phoneSwitch == "2") {
							return "关";
						}
					},
					editor : "select",
					options : phone_options
				}, {
					id : "phone",
					header : "手机号",
					fillspace : true,
					sort : "string",
					editor : "text"
				},{
					id : "mss_desc",
					header : "描述",
					fillspace : true,
				}
				,
				// 删除
				],
				select : true,
				editable : false,
				checkboxRefresh : true,
				tooltip : true,
				// url:当是外来数据时用这个
			// data:my_class,
			};
			var web = {
				container : "body",
				type : "line",
				id : "mylayout",
				rows : [ my_template, my_toolbar, my_datatable ],
			};
			webix.ui(web);// ---webix.ui结束----
			console.log( $$('mydatatable').count());
		
			webix.ajax().post("getMessageSet", "", function(text, xml, xhr) {
				var text1 = JSON.parse(text);
				if(text1.data!=""){
				$$("mydatatable").clearAll();
				$$("mydatatable").define("data", text1.data);
				$$('mydatatable').refresh();
				}else{
				$$("mydatatable").clearAll();
				$$("mydatatable").define("url", "../public/json/notify.json");
				$$('mydatatable').refresh();
				}
			})
		});
 

function updateRow() {
	$$('mydatatable').define("editable", "true");
	$$('mydatatable').eachRow(function(row) {
		$$('mydatatable').editRow(row);
	})
	$$('mydatatable').refresh();
}

function save() {
	var params = new Array();
	var dt = $$("mydatatable");
	dt.editStop();
	var ps = {};
	var arr = new Array();
	var i = 0;
	dt.eachRow(function(row) {
				var rows = dt.getItem(row);
				var r = {};
				r["title"] = rows.title;
				r["alias"] = rows.alias;
				r["emailSwitch"] = rows.emailSwitch;
				r["phoneSwitch"] = rows.phoneSwitch;
				r["phone"] = rows.phone;
				r["email"] = rows.email;
				r["mss_desc"] = rows.mss_desc;

				arr[i] = r;
				i++;
				params.push(rows.title,rows.alias, rows.emailSwitch, rows.phoneSwitch,
						rows.phone,rows.email,rows.mss_desc);
			});
	console.log(arr);
	ps["data"] = arr; 
	webix.ajax().post("setMessageSet", ps, function(text, xml, xhr) {
		var retData = JSON.parse(text);
		if (retData.ret < 0) {
			alert(retData.msg);
			location.reload();
		} else {
			alert("执行完毕");
			location.reload();
		}
	});
}
